# -*- coding: utf-8 -*-
"""
date: Thu Dec 13 09:57:31 2018
python: Anaconda 3.6.5
author: kanade
email: kanade@blisst.cn
"""
import numpy as np
import matplotlib.pyplot as mp

# 生成一个包含1000个数的等差数列，起始值为-π，终止值为π
x = np.linspace(-np.pi, np.pi, 1000)
# 计算y坐标数组
cosy = np.cos(x)
siny = np.sin(x)
# 设置坐标范围
mp.xlim(-np.pi, np.pi)
mp.ylim(-1, 1)
# 设置坐标刻度
mp.xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
          [r'$-\pi$', r'$-\frac{\pi}{2}$', r'$0$',
           r'$\frac{\pi}{2}$', r'$\pi$'])
mp.yticks([-1, -0.5, 0, 0.5, 1])
# 获取当前坐标系
ax = mp.gca()
# 设置位置
ax.spines['left'].set_position(('data',0))
ax.spines['bottom'].set_position(('data',0))
# 设置上右坐标轴不显示
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# 画线
mp.plot(x, cosy, linestyle='-.', linewidth=0.5,
        color='dodgerblue',label=r'$y=cos x$')
mp.plot(x, siny, linestyle=':', linewidth=3,
        color='orangered', label=r'$y=sin x$')

mp.legend(loc='lower right')
# 显示
mp.show()